package com.example.module_test

import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import com.example.lib_common.base.BaseActivity
import com.example.lib_common.state.UIState
import com.example.module_test.databinding.ActivityMain2Binding
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch

class MainActivity2 : BaseActivity<MainViewModel,ActivityMain2Binding>(){
    override val mPageCanBack: Boolean
        get() = false
    override val mLayoutResId: Int
        get() = R.layout.activity_main2
    override val mViewModel: MainViewModel by viewModels ()

    private val flow: MutableStateFlow<UIState> = MutableStateFlow(UIState.Default)

    override fun initView() {
    }

    override fun initData() {
        //模拟网络请求，更改state
        lifecycleScope.launch {
            flow.emit(UIState.Loading)
            delay(7000)
            flow.emit(UIState.Success)
            hideKeyBroad(mBinding.et)
        }

    }

    override fun initListener() {
        //收集state流
        addCommonStateListener(flow)
        //不是编辑框默认/自定义view不弹出软键盘
        mBinding.tv.setOnClickListener {
            showKeyBroad(mBinding.tv)
        }
        mBinding.tv2.setOnClickListener {
            startActivity(Intent(this,MainActivity3::class.java))
        }
    }

}